// pages/tabBar/my/component/myCollect/myCollect.js
import {request,fomatForCollect} from "../../../../../utils/util.js"
const { $Message } = require('../../../../../dist/base/index');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    fileList: [],  //文件列表
    classifyType: "collect",  //文件状态
    visible1: false,   //+号的弹窗显示
    isLoading:true,   //开局加载
    actions1: [        //加号里的内容
      {
        name: '新建收藏文件夹',
        color: "#487ff8"
      },
    ],
    visibleCreate: false //似乎好像没用
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.setStorageSync('location', "collect")
    this.getFileList();
  },


  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    const that = this
    const param = {
      type:this.data.classifyType
    }
    request("GET","/api/service/catalog",param).then(res =>{
      const data = res.data.data;
      const newData = fomatForCollect(data)
        that.setData({
          fileList:newData
        })
        wx.stopPullDownRefresh()
        
    })
  },

    /**
   * 获取数据的封装
   */
  getFileList(){
    
    const that = this
    const param = {
      type:this.data.classifyType
    }
    request("GET","/api/service/catalog",param).then(res =>{
     
      const data = res.data.data;
      const newData = fomatForCollect(data)
     
        that.setData({
          fileList:newData,
          isLoading:false
        })
       
    })
  },
  /**
     * 打开上啦菜单
     */
    add(){
      this.setData({
        visible1: true
    });
    },
    /**
     * 关闭上啦菜单
     */
    handleCancel1 () {
        this.setData({
            visible1: false
        });
    },
    /**
     * 上啦框里的各个事件
     * @param {}} param0 
     */
    handleClickItem1 ({ detail }) {
          this.selectComponent("#inputModal").setShow()
      
    },
    /**
     * 测试用调用展示MSg
     * @param {*} e 
     */
    showMsg:function(e){
     
      const mes = e.detail
      $Message({
        content: mes
    });
    }
})